<link rel="stylesheet" type="text/css" href="/css/chosen.css" media="screen, projection" />
<script charset="utf-8" src="/js/kindeditor-min.js" type="text/javascript"></script>
<script charset="utf-8" src="/js/kindeditor_zh_TW.js" type="text/javascript"></script>
<script src="/js/chosen.jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="/js/jquery.uploadify.v2.1.4.min.js"></script>
<script type="text/javascript">
	$(function(){
			KindEditor.ready(function(K) {
				K.create('#ClientIntro', {
					width: '100%',
					langType : 'zh_TW',
					items : [
                'source', '|', 'fullscreen', 'undo', 'redo', 'print', 'cut', 'copy', 'paste',
                'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
                'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
                'superscript', '|', 'selectall', '|',
                'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
                'italic', 'underline', 'strikethrough', 'removeformat', '|',
                'flash', 'media', 'table', 'hr', 'link', 'unlink' ]
				});
			});		
		$(".chzn-select").chosen();
		$("#ClientPhone").onlyNumber();
		$("#uploadify").uploadify({
			'uploader'       : '/js/uploadify.swf',
			'script'         : '/api-upload.html?action=ClientUpload',
			'cancelImg'      : '/images/cancel.png',
			'buttonImg'			 : '/images/buttons_bg02.png',
			'folder'         : 'upload',
			'fileExt'				 : '*.jpg',
			'queueID'        : 'fileQueue',
			'fileDesc'    	 : 'Image Files',
			'auto'           : true,
			'queueSizeLimit' : 1,
			'multi'          : false,
			'sizeLimit'			 : '5242880',
			onComplete: function(event, queueID, fileObj, reposnse, data) {
					if( fileObj.type.toLowerCase() == '.jpg' )
					{
						//updateAvatar(<{$avatar}>, reposnse);
						//$.post("/api-avatar.html", { status: "upload", avatar: "<{$avatar}>", val : reposnse }, function(){  });
						rep = eval("(" + reposnse + ")");
						var ClientLogoImg = '<img src="/tmp/'+rep.thumb+'" />';
						$("#ClientLogo").val(rep.thumb);
						$("#ClientLogoImg").html(ClientLogoImg);
					}else
					{
						alert("很抱歉!上傳圖片只能是jpg格式.");
					}
			}
		});	
		
		//POST FORM
		$("#createform").submit(function(){
			$("span.error").html('');
			
      if ($.trim($("#ClientUnit").val()) == "") {
				$(".ClientUnit").html('主辦單位名稱 不可為空');
				$("#ClientUnit").focus();
				return false;
			}
			
      if ($.trim($("#ClientName").val()) == "") {
				$(".ClientName").html('聯絡人 不可為空');
				$("#ClientName").focus();
				return false;
			}			
			
      if ($.trim($("#ClientPhone").val()) == "") {
				$(".ClientPhone").html('聯絡電話 不可為空');
				$("#ClientPhone").focus();
				return false;
			}
			
      if ($.trim($("#ClientEmail").val()) == "") {
				$(".ClientEmail").html('Email 不可為空');
				$("#ClientEmail").focus();
				return false;
			}
			
			if( isEmail($("#ClientEmail").val()) == false )
			{
				$(".ClientEmail").html('Email 格式錯誤');
				$("#ClientEmail").focus();
			}
			
      if ($.trim($("#ClientAddr").val()) == "") {
				$(".ClientAddr").html('聯絡地址 不可為空');
				$("#ClientAddr").focus();
				return false;
			}			
			return true;			
		});	 	
	});
	function isEmail(email) {
		var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (regex.test(email)) return true;
		else return false;
	}		
</script>
<div id="wrapper">
	
	<div id="main_content" class="left">
		
		<div id="con_mainbox">
			<div id="con_mainbox_in">
					
					<ul class="mainbox_curlink">
						<li class="left"><a href="/index.html"> 首頁 </a></li>
						<li class="left"><a href="/dashboard/client.html"> 管理主辦單位 </a></li>
						<{if $action == 'create'}>
						<li class="left"> 建立主辦單位 </li>
						<{elseif $action == 'edit'}>
						<li class="left"> <a href="/client-<{$aryData.cid}>.html" target="_blank"><{$aryData.cunit}></a> </li>
						<li class="left"> 編輯主辦單位 </li>
						<{/if}>
					</ul>		
					
					
					
					<table border="0" cellpadding="0" cellspacing="0" width="100%" class="table sortable">
						<tbody>
							<tr>
								<th width="100%">
									<{if $action == 'create'}>
									<h3> 建立主辦單位 </h3>
									<{elseif $action == 'edit'}>
									<h3> 編輯主辦單位 - <{$aryData.cunit}> </h3>
									<{/if}>
									</th>
							</tr>
							<tr class="no_items">
								<td>
									<form name="createform" id="createform" action="client.html" method="POST" enctype="multipart/form-data">
										<input type="hidden" name="action" value="save" />
										<input type="hidden" name="ClientLogo" id="ClientLogo" value="<{$aryData.clogo}>" />
										<div class="frmfiled_bk">
											<label for="ClientUnit" class="frm-required"> 主辦單位名稱： </label><span class="ClientUnit error"></span>
											<div class="frmfields_elm">
												<input type="text" name="ClientUnit" id="ClientUnit" value="<{$aryData.cunit}>" class="text medium" tabindex="1" />	
											</div>
										</div>
										
										<div class="frmfiled_bk">
											<label for="ClientPages"> Facebook粉絲團： </label>
											<div class="frmfields_elm">
												<select data-placeholder="選擇粉絲團" name="ClientPages" id="ClientPages" class="chzn-select" style="width:250px;" tabindex="2">
													<option value="">選擇粉絲團</option>
													<{section name="p1" loop=$FBPages}>
													<option value="<{$FBPages[p1].id}>|<{$FBPages[p1].name}>" <{if $aryData.cpages_id == $FBPages[p1].id}>selected<{/if}> ><{$FBPages[p1].name}></option>
													<{/section}>
												</select>	
											</div>
										</div>										
										
										<div class="frmfiled_bk">
											<label for="ClientName" class="frm-required"> 聯絡人： </label><span class="ClientName error"></span>
											<div class="frmfields_elm">
												<input type="text" name="ClientName" id="ClientName" value="<{$aryData.cname}>" class="text small" tabindex="3" />	
											</div>
										</div>
										
										<div class="frmfiled_bk">
											<label for="ClientPhone" class="frm-required"> 聯絡電話： </label><span class="ClientPhone error"></span>
											<div class="frmfields_elm">
												<input type="text" name="ClientPhone" id="ClientPhone" value="<{$aryData.cphone}>" class="text small" tabindex="4" />	
											</div>
										</div>
										
										<div class="frmfiled_bk">
											<label for="ClientEmail" class="frm-required"> Email： </label><span class="ClientEmail error"></span>
											<div class="frmfields_elm">
												<input type="text" name="ClientEmail" id="ClientEmail" value="<{$aryData.cemail}>" class="text medium" tabindex="5" />	
											</div>
										</div>																														
										
										<div class="frmfiled_bk">
											<label for="ClientAddr" class="frm-required"> 聯絡地址： </label><span class="ClientAddr error"></span>
											<div class="frmfields_elm">
												<input type="text" name="ClientAddr" id="ClientAddr" value="<{$aryData.caddr}>" class="text medium" tabindex="6" />	
											</div>
										</div>
										
										<div class="frmfiled_bk">
											<label for="ClientWebsite" class=""> 官方網站： </label>
											<div class="frmfields_elm">
												<input type="text" name="ClientWebsite" id="ClientWebsite" value="<{$aryData.cwebsite}>" class="text medium" tabindex="7" />	
											</div>
										</div>			
										
										<div class="frmfiled_bk">
											<label for="ClientWebsite" class=""> 商標圖示： </label>
											<div class="frmfields_elm">
												<input type="FILE" name="ClientUpload" id="uploadify" class="text medium" />
												<div id="fileQueue"></div>
												<div id="filesUploaded"></div>
												<div id="ClientLogoImg">
												<{if $aryData.clogo}><img src="/tmp/<{$aryData.clogo}>"/><{/if}>	
												</div>
												<p> 限制寬度 165px，大小不可超過 3Mb </p>
											</div>
										</div>	
										
										<div class="frmfiled_bk">
											<label for="ClientIntro" class=""> 主辦單位簡介： </label>
											<div class="frmfields_elm">
												<textarea name="ClientIntro" id="ClientIntro" style="height:200px;" tabindex="8"><{$aryData.cintro}></textarea>
											</div>
										</div>										
										
										<div class="frmfiled_bk">
											<span class="submit-button left"><input type="submit" name="submit" id="submitBtn" class="bg" value=""></span>
											<span class="reset-button left"><input type="reset" name="reset" id="resetBtn" class="bg" value=""></span>
										</div>
																																
									</form>
								</td>
							</tr>
						</tbody>	
					</table>
					
			</div>
		</div>
		
	</div>
	
	<{include file="slide_left.html"}>
</div>